module.exports = function ($scope, $state, $resource, $modal, toaster) {
	$scope.myKeyup = function (e) {
		//IE 编码包含在window.event.keyCode中，Firefox或Safari 包含在event.which中
		var keycode = window.event ? e.keyCode : e.which;
		if (keycode == 13) {
			$scope.loadlist();
		}
	};
		/* 分页
   * ========================================= */
  $scope.maxSize = 5;            //最多显示多少个按钮
  $scope.bigCurrentPage = 1;      //当前页码
  $scope.itemsPerPage = 10; 
  $scope.searchform = {};
	//卡列表
	$scope.loadlist = function () {
    var para = {
        pageNo:$scope.bigCurrentPage, 
        pageSize:$scope.itemsPerPage,
        state : '0'
    };
    para = angular.extend($scope.searchform, para);
		$resource('/api/as/mc/userrole/getShopApplyList', {}, {}).save(para, function (res) {
			if (res.errcode === 0) {
        $scope.objs = res.data.results;
        $scope.bigTotalItems = res.data.totalRecord;
			} else {
				toaster.error({ title: '', body: res.errmsg });
			}
		});
	}

	$scope.loadlist();

	// 邀请分销商
  var qrcode = '';
  var url = '';
  console.log(window.location.host);
  if (window.location.host == 'tsv.juyouhx.com'){
    url = 'https://weixint.juyouhx.com/views/distributor/apply_distributor.html?cid='
  } else {
    url = 'https://dlqt.juyouhx.com/skv4/views/distributor/apply_distributor.html?cid='
  }
  var cid = '';
  var pwx = 0;
  $resource('/api/ac/mc/merchantUserShopService/getcid', {}, {}).save({}, function (res) {
    if (res.errcode === 0) {
      console.log(res.data);
      cid = res.data.cid;
      qrcode = url + cid + '&' + 'pwx=0';
      console.log('qrcode' + qrcode);
    } else {
      toaster.error({ title: '', body: res.errmsg });
    }
  });
  $scope.add = function (){
        var modalInstance = $modal.open({
          template: require('../views/skwxOrcode1.html'),
          controller: 'skwxOrcode1',
          size: 'sm',
          resolve: {
            qrcode: function () {
              return qrcode;
            }
          }
        });
        modalInstance.result.then(function () {
          $scope.loadlist();
        });
  }

  $scope.agree = function (obj){
      if (confirm('确定通过该申请吗?')){
          $resource('/api/ac/mc/merchantUserRoleService/updateShopApplyYes', {}, {}).save({'id' : obj.id}, function (res) {
            if (res.errcode === 0) {
              toaster.success({ title: '', body: '申请成功' });
              $scope.loadlist();
            } else {
              toaster.error({ title: '', body: res.errmsg });
            }
          });
      }
  }
  $scope.disagree = function (obj){
      if (confirm('确定拒绝该申请吗?')){
          $resource('/api/ac/mc/merchantUserRoleService/updateShopApplyNo', {}, {}).save({'id' : obj.id}, function (res) {
            if (res.errcode === 0) {
              toaster.error({ title: '', body: '拒绝成功' });
              $scope.loadlist();
            } else {
              toaster.error({ title: '', body: res.errmsg });
            }
          });
      }
  }

};